package game;

import javax.vecmath.*;

import sceneGraph.*;

public class Enemy2 extends AbstractPlanetObject implements ISceneObject, IIntersectable, IEnemy {
	private static Color3f color = new Color3f(0.8f, 0.0f, 0.8f);

	private int counter;
	private Vector3f sideVector = new Vector3f(0, 0, 0);

	public Enemy2(Point3f pos) {
		super(pos, 0.1f, "/images/other/pear.off", 0.01f, color, color, color, 10);
	}

	public void advanceTowards(Point3f p) {
		Vector3f toPlayer = new Vector3f();
		toPlayer.sub(p, pos);
		toPlayer.normalize();
		toPlayer.scale(0.1f);

		// Disorient enemy with 50% probability
		counter++;
		if (counter == 10) {
			if (Math.random() < 0.5f) {
				Vector3f up = new Vector3f(pos);
				up.normalize();

				sideVector.cross(up, toPlayer);
				sideVector.normalize();
			} else {
				sideVector.set(0, 0, 0);
			}
			counter = 0;
		}

		toPlayer.add(sideVector);
		toPlayer.normalize();
		toPlayer.scale(0.08f);
		pos.add(toPlayer);
	}

	@Override
	public void accept(Visitor visitor) {
		visitor.visit(this);
	}

}
